using UnityEngine;
using UnityEngine.Networking;

// 资源包代理
public class AssetBundleAgent : AgentContext<AssetBundleAgent, UFrame.AssetBundles.AssetBundleController>
{
    protected bool m_inited;

    protected string GetStreamingAssetPathUrl()
    {
        var url = Application.streamingAssetsPath;
        if (Application.platform != RuntimePlatform.Android &&
            Application.platform != RuntimePlatform.WebGLPlayer)
        {
            url = "file:///" + url;
        }
        return url;
    }

    public static void StatInitialize(bool simulate)
    {
        if (!Context.m_inited)
        {
#if UNITY_EDITOR
            if (simulate)
            {
                Instance.SetCustomLoader(new UFrame.AssetBundles.SimulationLoader());
            }
#endif
            Context.m_inited = true;
            var url = Context.GetStreamingAssetPathUrl();
            Instance.StartUpWeb(Application.streamingAssetsPath + "/AssetBundles", "AssetBundles", Context.OnInitCallBack);
        }
    }

    private void OnInitCallBack(bool ok)
    {
        if (!ok)
        {
            Debug.LogError("AssetBundleAgent init failed!");
        }
        else
        {
            Debug.Log("AssetBundleAgent init ok");
            AgentSelf.SetInited();
        }
    }
}